
cc.Class({
    extends: cc.Component,

    properties: {
        scoreNode: cc.Node,
        petMgrNode: cc.Node,
    },



    onLoad() {
        this.scoreNodeJs = this.scoreNode.getComponent("Score");
        this.node.on("click", this.activePet, this);
        this.consumScore = 20;
    },

    start() {

    },

    update(dt) {
        this.curScore = this.scoreNodeJs.curScore;
        this.petNode = cc.find("Canvas/player/petMgr/pet");
        if (this.curScore >= this.consumScore && !this.petNode) {
            this.node.opacity = 150;
            cc.tween(this.node)
                .delay(0)
                .by(3, { angle: -360 })
                .start()
        }
        else if (this.curScore < this.consumScore || this.petNode) {
            this.node.opacity = 0;
        }
    },

    //激活宠物
    activePet() {
        if (this.curScore >= this.consumScore && !this.petNode) {
            this.scoreNodeJs.reduceScore(this.consumScore);
            let petMgrJs = this.petMgrNode.getComponent("PetMgr");
            petMgrJs.createPet();
        }
    }

});
